package com.uzhie.spring;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by TangFei on 2018/8/16.
 */
public class HttpSpringWrapperFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        logger.info("enter HttpSpringWrapperFilter method doFilterInternal");
        HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(httpServletRequest);
        HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(httpServletResponse,requestWrapper);
        filterChain.doFilter(requestWrapper, responseWrapper);
        logger.info("after doFilter " + responseWrapper.getResponseJSON());
    }
}
